<script setup>
import { useMemberStore } from '../../stores/modules/member';
import { getCurrentInstance } from 'vue';
import {reqLogin,reqUserInfo} from '../../api/login.js'
import {xtzDebounce,timerId} from '/utils/xtzDebounce.js'
const {proxy} = getCurrentInstance()
const memberStore = useMemberStore()
const login = ()=>{
	xtzDebounce(getPower,800)()
}

const getPower = ()=>{
	uni.login({
		success: async({code}) => {			
			if(code){
				const {data} = await reqLogin(code)
				memberStore.setToken(data.token)
				await getUserInfo()
			}else{
				proxy.$toast({title:'授权失败，请重新授权'})
			}
		}
	})
	console.log(1111);
}
const getUserInfo = async()=>{
	const {data} = await reqUserInfo()
	memberStore.setProfile(data)
	uni.switchTab({
		url:'/pages/my/my'
	})
}
</script>

<template>
	<view class="login">
		<image class="img" src="../../static/userAva.png"></image>
		<view class="desc">
			尊敬的用户您好，您还未登录，请点击按钮登录。
		</view>
		<button class="login-btn" type="warn" @click="login">点击登录</button>
	</view>
</template>

<style lang="scss" scoped>
.login{
	display: flex;
	flex-direction: column;
	align-items: center;
	padding-top: 32vh;
	.img{
		width: 100rpx;
		height: 100rpx;
		margin-bottom:20rpx;
	}
	.desc{
		font-size: 26rpx;
		color: #8f8f8f;
		margin-bottom:20rpx;
	}
	.login-btn{
		border-radius: 50rpx;
	}
}
</style>
